let readlineSync = require("readline-sync");
let checkinput = require("./Component/isCorrect");
let booking = require("./Component/writeData");
let cencel = require("./Component/cancelBook");
let income = require("./Component/printIncome");
//控制函数运行的变量
let exit = false;
//初始化全局变量
let customerList = {
    "A": {},
    "B": {},
    "C": {},
    "D": {}
};
while (exit !== true) {
    let userInput = readlineSync.question("");
    switch (userInput) {
        case "":
            console.log(income.printIncome(customerList));
            break;
        case "help":
            console.log("目前系统支持的命令\n[1]help\n[2]直接回车\n[3]see\n[4]exit");
            break;
        case "exit":
            exit = true;
            break;
        case "see":
            console.log(JSON.stringify(customerList));
            break;
        default:
            let result = checkinput.isCorrect(userInput);
            if (typeof(result) === 'string') {
                console.log(result);
            } else {
                switch (result.method) {
                    case "cancel":
                        let isCancel = cencel.cancelBook(customerList, result.data);
                        if (typeof(isCancel) === "string") {
                            console.log(isCancel)
                        } else {
                            customerList = isCancel;
                            console.log("Success: the booking is accepted!");
                        }
                        break;
                    case "booking":
                        let message = booking.writeData(customerList, result.data);
                        if (typeof(message) === "string") {
                            console.log(message);
                        } else {
                            customerList = message;
                            console.log("Success: the booking is accepted!");
                        }
                        break;
                    default:
                        break;
                }
            }
            break;
    }
}